package com.atguigu.springcloud.bean;

import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.cloud.gateway.route.CachingRouteLocator;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;

public class Push extends CachingRouteLocator {

    @Resource
    private ApplicationEventPublisher publisher;

    public Push(RouteLocator delegate) {
        super(delegate);
    }

    @Override
    public Flux<Route> refresh() {
        return super.refresh();
    }

    @Override
    public void onApplicationEvent(RefreshRoutesEvent event) {
        super.onApplicationEvent(event);
    }

    @GetMapping("/test")
    public String test() {
        publisher.publishEvent(new RefreshRoutesEvent(new Object()));
        return "success";
    }
}
